<?php
$types = array(
	'text',
	'photo',
	'quote',
	'link',
	'chat',
	'video'
	); 

$options = (array) get_option('tumblelog');

class Theme {
	function init() {
		//$exclude = '';
		$this->include_all(TEMPLATEPATH . '/app/includes/', $exclude);
		$this->include_all(TEMPLATEPATH . '/app/classes/', $exclude);	
	}

	function include_all($dir_path, $exclude = false) {
		$dir = @dir($dir_path) or die('Could not open required directory ' . $dir_path);

		while (($file = $dir->read()) !== false) {
			if (is_file($dir_path . $file) && (!$exclude || !in_array($file, $exclude)) && preg_match('/\.php$/i', $file)) {
				require_once($dir_path . $file);
			}
		}

		$dir->close();
	}
		
	function install() {
		$defaults = array(
			'description' => '',
			'menu' => '0',
			'text' => '0',
			'photo' => '0', 
			'quote' => '0',
			'link' => '0',
			'chat' => '0',
			'video' => '0'
			);
		
		foreach ($defaults as $name => $value)
			if (!isset($options[$name]))
				$options[$name] = $value;
	
		add_option('tumblelog', $options);
	}
	
	function uninstall() {
		global $wpdb;

		update_option('template', 'default');
		update_option('stylesheet', 'default');
		
		do_action('switch_theme', 'Default');
		
		delete_option('tumblelog');
		
		wp_cache_flush();

		wp_redirect('themes.php');
		exit();
	}
}

$Theme = new Theme();
$Theme->init();
?>